package com.example.myspring.util;

import javax.servlet.http.HttpServletRequest;


//该类为验证码工具类  用于验证码是否正确
public class CaptchaUtil {

    public static boolean verify(String userInput, HttpServletRequest req){
        String generatedCaptcha = (String) req.getSession().getAttribute("captcha");
        //非空判断
        if(userInput != null && !userInput.isEmpty() && generatedCaptcha != null && !generatedCaptcha.isEmpty()){
            //比对 返回true或false
            return userInput.equalsIgnoreCase(generatedCaptcha);
        }
        return false;
    }
}
